package kin.system.util;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.web.bind.WebDataBinder;

public class DatePropertyEditor extends PropertyEditorSupport {  
    
    
   
    public void InitBinder(WebDataBinder dataBinder)  
    {  
        dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() {  
            public void setAsText(String value) {  
                try {  
                    setValue(new SimpleDateFormat("yyyy-MM-dd").parse(value));  
                } catch(ParseException e) {  
                    setValue(null);  
                }  
            }  
      
            public String getAsText() {  
                return new SimpleDateFormat("yyyy-MM-dd").format((Date) getValue());  
            }          
      
        });  
    }  
      
}  
